Skip to content

[AIT-681] Compute fork metadata for edits via useChat#37

Open
lawrence-forooghian wants to merge 2 commits intomainfrom
AIT-681-passing-messageId-to-send
Open

[AIT-681] Compute fork metadata for edits via useChat#37
lawrence-forooghian wants to merge 2 commits intomainfrom
AIT-681-passing-messageId-to-send

Conversation

@lawrence-forooghian
Copy link
Copy Markdown
Contributor

@lawrence-forooghian lawrence-forooghian commented Apr 10, 2026

Summary

Our SDK has two forking operations: edit (replace a user message) and regenerate (re-run an assistant message). The AI SDK's useChat exposes the same two: sendMessage with a messageId (edit) and regenerate(). We already made our regenerate compatible with useChat's — ChatTransport computes forkOf/parent from the conversation tree when trigger is regenerate-message.

It turns out we missed the edit case. Without fork metadata, edits via useChat were treated as new messages rather than forks in the conversation tree.

We fix it by always including fork metadata when the messageId is provided, regardless of the presence of a trigger, thus continuing to cover the regeneration case and now also the edit case.

Demo

The demo app used for the videos below is on a separate branch: AIT-681-edit-demo (demo/vercel/react/edit-demo/).

Normal useChat edit (plain Vercel, no Ably transport)

2026-04-10.16-56-51.mov

useChat edit with our transport — before fix (broken)

2026-04-10.17-00-19.mov

useChat edit with our transport — after fix (working)

2026-04-10.17-06-03.mov

AIT-681

🤖 Generated with Claude Code

@lawrence-forooghian lawrence-forooghian changed the title Compute fork metadata for edits via useChat Compute fork metadata for edits via useChat Apr 10, 2026
@lawrence-forooghian lawrence-forooghian changed the title Compute fork metadata for edits via useChat [AIT-681] Compute fork metadata for edits via useChat Apr 10, 2026
@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch 5 times, most recently from 310350c to 537fc2f Compare April 13, 2026 12:36
Comment thread src/vercel/transport/chat-transport.ts Outdated
@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch from 537fc2f to 84a1346 Compare April 13, 2026 14:59
@github-actions github-actions bot temporarily deployed to staging/pull/37/typedoc April 13, 2026 15:00 Inactive
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 92.62% 2086 / 2252
🔵 Statements 90.94% 2231 / 2453
🔵 Functions 93.18% 383 / 411
🔵 Branches 77.9% 945 / 1213
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/vercel/transport/chat-transport.ts 100% 95.83% 100% 100%
Generated in workflow #139 for commit 7b9046e by the Vitest Coverage Report Action

@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch from 84a1346 to f1815e4 Compare April 13, 2026 15:02
@github-actions github-actions bot temporarily deployed to staging/pull/37/typedoc April 13, 2026 15:03 Inactive
@lawrence-forooghian lawrence-forooghian marked this pull request as ready for review April 13, 2026 15:05
@lawrence-forooghian lawrence-forooghian requested review from a team and kaschula and removed request for a team April 13, 2026 15:05
@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch from f1815e4 to c37bb72 Compare April 13, 2026 16:01
@github-actions github-actions bot temporarily deployed to staging/pull/37/typedoc April 13, 2026 16:01 Inactive
Copy link
Copy Markdown
Contributor

@kaschula kaschula left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. I have tested on your demo branch.

I do have a question. Do you plan to merge you demo or integrate the edit functionality into the current demos?

@lawrence-forooghian
Copy link
Copy Markdown
Contributor Author

I do have a question. Do you plan to merge you demo or integrate the edit functionality into the current demos?

I hadn't planned to; do you think it would be useful?

@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch from c37bb72 to 2874307 Compare April 14, 2026 17:31
@github-actions github-actions bot temporarily deployed to staging/pull/37/typedoc April 14, 2026 17:32 Inactive
Our SDK has two forking operations: edit (replace a user message)
and regenerate (re-run an assistant message). The AI SDK's useChat
exposes the same two: sendMessage with a messageId (edit) [1] and
regenerate(). We already made our regenerate compatible with
useChat's — ChatTransport computes forkOf/parent from the
conversation tree when trigger is 'regenerate-message'.

It turns out we missed the edit case. Without fork metadata,
edits via useChat were treated as new messages rather than forks
in the conversation tree.

We fix it by always including fork metadata when the messageId is
provided, regardless of the trigger, thus continuing to cover the
regeneration case and now also the edit case.

[1] https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#send-message

[AIT-681]

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lawrence-forooghian lawrence-forooghian force-pushed the AIT-681-passing-messageId-to-send branch from 2874307 to 8cc3b51 Compare April 15, 2026 16:20
@github-actions github-actions bot temporarily deployed to staging/pull/37/typedoc April 15, 2026 16:21 Inactive
Wire useChat's sendMessage({ messageId }) through the demo UI so that
user messages can be edited inline. Clicking "edit" on a user bubble
opens a textarea pre-filled with the original text; "Save & send"
calls sendMessage with the messageId, triggering the submit-message
edit flow through ChatTransport.

Not yet tested — intended to be squashed into the preceding commit
(8cc3b51) once verified.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@lawrence-forooghian
Copy link
Copy Markdown
Contributor Author

I've rebased on main and added edit support to the useChat demo but am currently unable to test it due to the demo apps being broken (I think @ttypic is looking at this); commit 7b9046e is to be tested and squashed once main is working

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants